
package cn.le.studyEnum;
/**
 * switch语句中的enum
 */
public enum SwitchEnum {

    GREEN,YELLOW,RED

}
class TrafficLight{


    SwitchEnum switchEnum = SwitchEnum.RED;

    public void change()
    {
        switch (switchEnum)
        {
            case RED:
                switchEnum = SwitchEnum.GREEN;
                 break;
            case GREEN:
                switchEnum = SwitchEnum.YELLOW;
                break;
            case YELLOW:
                switchEnum = SwitchEnum.RED;
                break;
        }
    }
    public String toString()
    {
        return "The traffic light is " +switchEnum;
    }

    public static void main(String[] args) {
        TrafficLight t = new TrafficLight();
        for (int i = 0, length = 7; i < length; i++) {
            System.out.println(t);
            t.change();
        }
    }


}